package kamikazehero.game.controller;

import javax.swing.JFrame;

import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Controller.Type;

import kamikazehero.constants.Constants;
import kamikazehero.data.DatabaseConnection;
import kamikazehero.game.entity.ControllableEntity;
import kamikazehero.game.score.GameScore;
import kamikazehero.game.view.GameView;
import kamikazehero.game.view.TestView;
import kamikazehero.game.window.GameWindow;
import kamikazehero.input.InputDevice;

/**
 * GameController.java
 * @author Hanshew
 *
 *
 */
public class GameController {
	
	private GameWindow gameWindow;
	private InputDevice inputDevice;
	private DatabaseConnection dbc;
	private TestView test;
	
	public GameController(){
		
		gameWindow = new GameWindow();
		test = new TestView(this.getInputController(), gameWindow.getPreferredSize());
		gameWindow.getContentPane().add(test);
		gameWindow.pack();
	}
	
	/**
	 * Gets an instance of a HID game controller
	 * 
	 * @return - a controller
	 */
	private Controller getInputController(){
		
		Controller controller = null;
		Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
    	
		for(int i = 0; i < controllers.length; i++){
			/*
			 * This may need to be changed if another controller is used
			 */
    		if(controllers[i].getType() == Controller.Type.STICK){
    			controller = controllers[i];
    		}
		}
		
    	return controller;
	}
	
	private void saveScore(GameScore score){
		try {
			dbc.addScore(score);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
